<?php

namespace App\Models;


use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class Card extends Model
{

    protected $table = 'card_list';
    public $timestamps = false;

    static function getDetailCard($id,$userid){
        $res = self::where('id',$id)->first();
        $causer_id = ClassCard::getCardById($userid);
        $userInfo = User::where('id',$userid)->first();
        if (empty($causer_id)){
            $v['class_status'] = 1;

        }else{
            if ($userInfo->level == 1 || ($userInfo->level == 0 && $causer_id->status ==0)){
                $res['class_status'] = 0;
            }else{
                $res['class_status'] = 1;
            }
        }

        return $res;
    }
//    public function getCardList($id){
//         //找到当前你人的报名列表
//         $causer_id = ClassCard::getCardById($id);
//         $card_list = self::all();
//         $userInfo = User::where('id',$id)->first();
//         foreach ($card_list as $k=>&$v){
//             if ($causer_id->status == 0){
//                 $v['class_status'] = 0;//可报名
//             }else{
//                 if (empty($causer_id)){
//                     $v['class_status'] = 1;//可报名
//                 }else{
//                     //判断是否再有效期内
//                     if ($userInfo->class_end_time){
//                         if (time()<$userInfo->class_end_time){
//                             $v['class_status'] = 0;
//                         }else{
//                             //在判断报名记录
//                             $v['class_status'] = 1;
//                         }
//                     }else{
//                         $v['class_status'] = 0;
//                     }
//                 }
//             }
//
//
//         }
//         return $card_list;
//    }
    public function getCardList($id){
        //找到当前你人的报名列表
        $causer_id = ClassCard::getCardById($id);
        $card_list = self::all();
        $userInfo = User::where('id',$id)->first();
        foreach ($card_list as $k=>&$v){
            //先判断当前身份
            if (empty($causer_id)){
                $v['class_status'] = 1;

            }else{
                if ($userInfo->level == 1 || ($userInfo->level == 0 && $causer_id->status ==0)){
                    $v['class_status'] = 0;
                }else{
                    $v['class_status'] = 1;
                }
            }

        }
        return $card_list;
    }

}
